<?php
namespace Modules\Activity\Http\Controllers\Client;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use \Modules\Agent\Entities\InviteRecord;
use \Modules\Agent\Entities\InviteRecord2;

use Validator;
use ThrowException;
use DB;
use Auth;
use Setting;

class InviteRecordController extends Controller
{
    // 获取活动邀请记录列表
    public function index(Request $req)
    {
        $rule = [
            'node_uuid' => ['required']
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $user = Auth::requireLoginUser();

        $options = [
            'where' => [
                'direct_inviter_id' => $user->id,
                'invite_node_uuid' => $req->node_uuid,
            ],
            'builder' => InviteRecord::whereHas('user'),
            'per_page' => $req->input('per_page', 10),
            'page' => $req->input('page', 1),
            'with' => ['user'],
            'only' => [
                'user' => [
                    'headimg',
                    'name'
                ],
                'node_invite_index',
                'node_reward',
                'created_at',
                'status'
            ]
        ];

        $list = InviteRecord::getList($options);

        return $list->generateListResponse();
    }

    // 获取活动邀请记录列表
    public function index2(Request $req)
    {
        $rule = [
            'node_uuid' => ['required']
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $user = Auth::requireLoginUser();

        $options = [
            'where' => [
                'direct_inviter_id' => $user->id,
                'invite_node_uuid' => $req->node_uuid,
            ],
            'builder' => InviteRecord2::whereHas('user'),
            'per_page' => $req->input('per_page', 10),
            'page' => $req->input('page', 1),
            'with' => ['user'],
            'only' => [
                'user' => [
                    'headimg',
                    'name'
                ],
                'node_invite_index',
                'node_reward',
                'created_at',
                'status'
            ]
        ];

        $list = InviteRecord2::getList($options);

        return $list->generateListResponse();

    }
}
